<?php

namespace app\api\controller;

use app\api\model\LangClassLessonRecite AS LessonReciteModel;

class LangClassLessonRecite extends Base
{
    /**
     * 通过班级id获取背诵模块所有单词或者句子 包括答案
     * @param $lessonId
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function index($lessonId)
    {
        // 类型，1背单词，2背句子
        $type = input('type');
        if (empty($lessonId)) {
            return self::sendResult(100, [], '请选择哪节课');
        }

        if (empty($type)) {
            return self::sendResult(100, [], '请选择背诵类型');
        }

        $oauthId = $this->oauthInfo['id'];
        $model = LessonReciteModel::getListByLesson($oauthId, $lessonId, $type);

        if (isset($model['noData']) && $model['noData'] === true) {
            return self::sendResult(129);
        }

        if ($model['isBuy'] === false) {
            return self::sendResult(109);
        }

        return self::sendResult(self::$okCode, [
            'list' => $model['list'],
            'count' => $model['count']
        ]);
    }
}